{% extends "extends/base_all_.html" %}


{% block content %}
<div class="container">
    <div class="row justify-content-center align-items-center min-vh-100">
        <div class="col-md-6 col-lg-4">
            <div class="card shadow">
                <div class="card-body p-5">
                    <div class="text-center mb-4">
                        <i class="bi bi-person-circle fs-1 text-primary"></i>
                        <h2 class="mt-3 mb-2">用户登录</h2>
                    </div>
                    <form id="form">
                        <div class="mb-3">
                            <label for="username_input" class="form-label" id="username">用户名</label>
                            <input type="text" class="form-control form-control-lg" id="username_input" placeholder="请输入用户名" required>
                        </div>
                        <div class="mb-3">
                            <label for="password_input" class="form-label" id="password">密码</label>
                            <input type="password" class="form-control form-control-lg" id="password_input" placeholder="请输入密码" required>
                        </div>
                        <button type="submit" class="btn btn-primary btn-lg w-100 mb-3" value="login_but">
                            <i class="bi bi-box-arrow-in-right me-2"></i>用户登录
                        </button>
                        <button type="submit" class="btn btn-outline-secondary btn-lg w-100" value="admin_but">
                            <i class="bi bi-shield-lock me-2"></i>管理员登录
                        </button>
                    </form>
                    <div class="d-flex justify-content-between mt-3">
                        <a href="#" class="text-decoration-none" id="register_a">注册新账户</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    onUrlsReady(urls => {
        Element_('register_a').href = urls.page.register;

        Event_('form', 'submit', event => {
            var data = Pack({
                'username_input': 'username',
                'password_input': 'password'
            })

            if(event.submitter.value === 'login_but'){
                Fetch(urls.service.login,'post',data,async res => {
                    await Flash(res.msg)
                    Redirect(urls.page.front.home);
                })
            }else{
                Fetch(urls.service.adminlogin,'post',data,async res => {
                    await Flash(res.msg)
                    Redirect(urls.page.back.check)
                })
            }

        });
    });
</script>

{% endblock %}
